module.exports = function($scope, $stateParams, $resource, $state, $modal){
	
	$scope.iface = [];

	init();
	function init(){
		$resource('/api/as/sc/sysfun/getById', {}, {}).save({'id': $stateParams.id}, function(res){
			if(res.errcode === 0){
				$scope.obj = res.data;
				$scope.getBindInterface($scope.obj.bind_other_function);
			}else{
				alert(res.errmsg);
			}
		});
	};

	//查询接口已绑定的其他接口
    $scope.getBindInterface = function(str){
		$resource('/api/as/sc/sysfun/getBindFunList', {}, {}).save({'bind_other_function': str}, function(res){
			if(res.errcode === 0){
				$scope.iface = res.data;
			}else{
				alert(res.errmsg);
			}
		});
    };

	//删除菜单的接口
    $scope.remove = function(index){
		$scope.iface.splice(index,1);
    };

	//保存
	$scope.save = function () {
		var a= [];
		for(var i = 0; i < $scope.iface.length; i++){
			a.push($scope.iface[i].id);
		}
		$scope.obj.bind_other_function = a.toString();
		$resource('/api/as/sc/sysfun/save', {}, {}).save($scope.obj, function(res){
			if(res.errcode === 0){
				$scope.cancel();
			}else{
				alert(res.errmsg);
			}
		});
	};

	//取消
	$scope.cancel = function () {
		$state.go('app.interfaceList', {});
	};



};